﻿using System;
using System.Runtime.InteropServices;

namespace LockScreen
{
    public class WinAPI
    {
        public const Int32 WM_KEYDOWN = 256;
        public const Int32 WM_SYSKEYDOWN = 260;
        public const UInt32 WM_SYSCOMMAND = 0x0112;
        public const UInt32 SC_MONITORPOWER = 0xF170;

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, UInt32 wParam, Int32 lParam);

        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern Boolean BlockInput([In, MarshalAs(UnmanagedType.Bool)]Boolean fBlockIt);

        [DllImport("user32.dll")]
        public static extern Boolean LockWorkStation();

        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr GetForegroundWindow();

        [DllImport("user32.dll", EntryPoint = "SetForegroundWindow")]
        public static extern Boolean SetForegroundWindow(IntPtr hWnd);

        [DllImport("user32.dll")]
        public static extern Boolean SetWindowPos(IntPtr hWnd, Int32 hPos, Int32 x, Int32 y, Int32 cx, Int32 cy, UInt32 nflags);
    }
}
